#include <bits/stdc++.h>
using namespace std;
using uint = unsigned int;
using ll = long long;
using ull = unsigned long long;
using i128 = __int128;
const int N = 1e6 + 5;

void solve() {
    int n, r;
    cin >> n;
    cin >> r;
    stack<char> st;
    while (n) {
        int temp = n % r;
        if (temp <= 9)
            st.push('0' + temp);
        else
            st.push('A' + (temp - 10));
        n /= r;
    }
    while (!st.empty()) {
        cout << st.top();
        st.pop();
    }
    cout << endl;
    return;
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    solve();

    return 0;
}